#define _CRT_SECURE_NO_WARNINGS 1

#include"Contact.h"


void InitContact(Contact* pc)
{
	assert(pc);
	pc->sz = 0;
	memset(pc->data, 0, sizeof(pc->data));
}


void AddContact(Contact* pc)
{
	assert(pc);
	if (pc->sz == MAX)
	{
		printf("通讯录已经满了，不能添加");
		return ;
	}
	printf("请输入姓名:>");
	scanf("%s", pc->data[pc->sz].name);
	printf("请输入年龄;>");
	scanf("%d", &pc->data[pc->sz].age);
	printf("请输入性别:>");
	scanf("%s", pc->data[pc->sz].sex);
	printf("请输入电话:>");
	scanf("%s", pc->data[pc->sz].tele);
	printf("请输入地址:>");
	scanf("%s", pc->data[pc->sz].addr);

	pc->sz++;
	printf("成功添加联系人\n");

}


void ShowContact(const Contact* pc)
{
	assert(pc);
	int i = 0;
	printf("%-10s\t%-5s\t%-5s\t%-12s\t%-20s\n", "姓名", "年龄","性别", "电话", "地址");
	for (i = 0; i < pc->sz; i++)
	{
		printf("%-10s\t%-5d\t%-5s\t%-12s\t%-20s\n", pc->data[i].name, pc->data[i].age, pc->data[i].sex, pc->data[i].tele, pc->data[i].addr);
	}
} 



void DelContact(Contact* pc)
{
	assert(pc);
	char arr[MAX] = { 0 };
	printf("请输入你要删除人的名字:>");
	scanf("%s", arr);
	//不存在
	int i = 0;
	int flag = 0;
	for (i = 0; i < pc->sz; i++)
	{
		int ret = strcmp(arr, pc->data[i]);
		if (ret == 0)
		{
			flag = 1;
			break;
		}
	}
	if (flag == 0)
	{
		return ;
	}
	//存在
	int j = 0;
	for (j = i; j < pc->sz - 1; j++)
	{
		pc->data[j] = pc->data[j + 1];
	}

}